package main

import (
	"fmt"
)

func main() {
	fmt.Println(letterCombinations("23"))
}
func letterCombinations(digits string) []string {
	var res [][]byte
	var list []byte
	m := map[int]string{
		0: "",
		1: "",
		2: "abc",
		3: "def",
		4: "ghi",
		5: "jkl",
		6: "mno",
		7: "pqrs",
		8: "tuv",
		9: "wxyz",
	}
	var helper func(digits string, list []byte, index int)
	helper = func(digits string, list []byte, index int) {
		if len(list) == len(digits) {
			tmp := make([]byte, len(list))
			copy(tmp, list)
			res = append(res, tmp)
			return
		}

		//byte数字转uint8数字
		//int(digits[index]-'0')
		j := digits[index] - '0'
		k := int(j)
		s := m[k]
		for i := 0; i < len(s); i++ {
			list = append(list, s[i])
			helper(digits, list, index+1)
			list = list[:len(list)-1]
		}
	}
	helper(digits, list, 0)
	o := []string{}
	for _, v := range res {
		o = append(o, string(v))
	}
	return o
}
